package ch07.shizhang.shizhang03;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.sun.activation.registries.LogSupport.log;

/**
 * @author 茜茜
 * @date 2024-11-27 20:39
 */
public class BusinessServiceProxy implements BusinessService{
    private final BusinessService businessService;

    public BusinessServiceProxy(BusinessService businessService) {
        this.businessService = businessService;
    }

    @Override
    public void performBusinessLogic() {
        // 添加前置日志
        log("Before business logic execution");

        // 调用实际的业务方法
        businessService.performBusinessLogic();

        // 添加后置日志
        log("After business logic execution");

    }
    private void log(String message) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timestamp = dateFormat.format(new Date());
        System.out.println("[LOG " + timestamp + "] " + message);
    }
}
